<!DOCTYPE html>
<html lang="en">
<head>
    <title>菜单编辑</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${base}/res/plugin/ztree/css/style.css" type="text/css">
    <link href="${base}/res/manage/css/common.css" rel="stylesheet">
    <link href="${base}/res/manage/css/ec.css" rel="stylesheet">
    <link href="${base}/res/manage/css/list.css" rel="stylesheet">
    <script type="text/javascript" src="${base}/static/res/plugin/jquery/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/validator/jquery.validate.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/plugin/ztree/js/jquery.ztree.exedit-3.5.min.js"></script>
    <script type="text/javascript" src="${base}/static/res/util/utils.js"></script>
    <script type="text/javascript" src="${base}/static/res/admin/js/common.js"></script>
    <script type="text/javascript" src="${base}/static/res/util/areaSelUtil.js"></script>
    <script type="text/javascript">
        //加载树形
        $(document).ready(function () {

            //树形选择函数
            $("#parentName").focus(function () {
                var areaSel = new AreaSelUtil({
                    webPath: '${base}',
                    cid: '#id',
                    id: '#parentId',
                    name: '#parentName',
                    activeId: 'parentName'
                });
                areaSel.showTree();
            });

            //清空父区域
            $("#clearParentArea").click(function () {
                $("#parentId").val("");
                $("#parentName").val("");
            });

            //表单验证，数据提交
            $("#inputForm").validate({
                rules: {
                    name: {
                        required: true,
                        maxlength: "200"
                    },
                    orders: {
                        min: 1,
                        digits: "true"
                    },
                    areaCode: {
                        digits: true
                    }

                },
                messages: {
                    name: {
                        required: "必填项",
                        maxlength: "菜单名字最长不超过200个字符"
                    },
                    orders: {
                        min: "至少为一位数字",
                        digits: "必须为数字"
                    },
                    areaCode: {
                        digits: "必须为数字"
                    }
                },
                submitHandler: function (form) {

                    var at = $("#inputForm").attr("action");
                    $(form).find(":submit").prop("disabled", true);

                    $.post($("#inputForm").attr("action"), $("#inputForm").serialize(), function (data) {

                        $(form).find(":submit").prop("disabled", false);
                        clearForm("#inputForm");
                        $.message(data.type, data.msg);

                        if (data.success) {
                            var o = data.data;
                            //强制刷新树形节点
                            var treeObj = parent.$.fn.zTree.getZTreeObj("treeDemo");
                            var tNode = treeObj.getNodeByParam("com.project.common.web.utils.id", com.project.common.web.utils.id, null);
                            var opNode = treeObj.getNodeByParam("com.project.common.web.utils.id", o.parentId, null);

                            if (!tNode) {
                                if (opNode) {
                                    opNode.isParent = true;
                                    treeObj.reAsyncChildNodes(opNode, "refresh");
                                } else if (!o.parentId) {
                                    treeObj.reAsyncChildNodes(null, "refresh");
                                }
                                return;
                            } else if (o.parentId && tNode.parentId) {

                                opNode = treeObj.getNodeByParam("com.project.common.web.utils.id", o.parentId, null);
                                if (opNode) {
                                    opNode.isParent = true;
                                    treeObj.reAsyncChildNodes(opNode, "refresh");
                                }

                                if (o.parentId != tNode.parentId) {
                                    var tpNode = treeObj.getNodeByParam("com.project.common.web.utils.id", tNode.parentId, null);
                                    if (tpNode) {
                                        tpNode.isParent = true;
                                        treeObj.reAsyncChildNodes(tpNode, "refresh");
                                    }
                                }

                            } else {
                                treeObj.reAsyncChildNodes(null, "refresh");
                                return;
                            }

                        }

                    }, "json");

                }
            });
        });
    </script>
</head>
<body>
[#--主体--]
<div class="tablist message set">
    <form id="inputForm" action="save.jhtml" method="post" name="inputForm">
    [#--隐藏字段--]
        <input name="parentId" id="parentId" type="hidden"/>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td><label>区域名称<span class="cred"> * </span></label></td>
                <td>
                    <input type="text" id="name" name="name" value="${area.name}" placeholder="区域名称">
                </td>

                <td><label>父级区域</label></td>
                <td>
                    <input type="text" id="parentName" name="parentName" class="uploadTxt" readonly="readonly" placeholder="请选择">
                    <input type="button" value="清空" id="clearParentArea" class="uploadBtn">
                </td>
            </tr>

            <tr>
                <td><label>区域编码</label></td>
                <td>
                    <input type="text" id="areaCode" name="areaCode" value="${area.areaCode}" placeholder="区域编码">
                </td>

                <td><label>车牌前缀</label></td>
                <td>
                    <input type="text" id="carPrefix" name="carPrefix" value="${area.carPrefix}" placeholder="车牌前缀">
                </td>
            </tr>
            <tr>
                <td><label>排序</label></td>
                <td>
                    <input type="text" id="orders" name="orders" value="${area.orders}" placeholder="排序">
                </td>
                <td><label>地区首字母</label></td>
                <td>
                    <input type="text" id="areaFirstLetter" name="areaFirstLetter" value="${area.areaFirstLetter}" placeholder="地区首字母">
                </td>
            </tr>
            <tr>
                <td><label>所属大区</label></td>
                <td>
                    <select id="region" name="region">
                        <option value="">请选择</option>
                        <option value="1">东北区</option>
                        <option value="2">华东区</option>
                        <option value="3">华北区</option>
                        <option value="4">华中区</option>
                        <option value="5">华南区</option>
                        <option value="6">西南区</option>
                        <option value="7">西北区</option>
                    </select>
                    <a href="javascript:;" class="arrows">∨</a>
                </td>
            </tr>

        </table>
        <p class="save">
            <input type="submit" value="保存" class="red">
        </p>
    </form>
</div>
</body>
</html>